
*********************************************************************************************************

***Do political leaders understand public opinion better than backbenchers?***

*Authors: 	Stefaan Walgrave, Julie Sevenans, Frederic Varone, Christian Breunig, Lior Sheffer
*Contact:   julie.sevenans@uantwerpen.be

*********************************************************************************************************

use "Replication data\Dataset.dta", clear

//Clean/recode IVs
gen age=.
replace age=2018-yob if V2~=6
replace age=2019-yob if V2==6

recode gov (1=0) (0=1), gen(opposition_party)

gen seniority=.
replace seniority=2018-yofe if V2~=6
replace seniority=2019-yofe if V2==6

rename nominations nr_nominations
recode nr_nominations (0=0) (1/100=1) (.=.), gen(dummy_nominations)

save "temp\dataset with IV.dta", replace


*************************A) GENERAL PUBLIC OPINION ESTIMATIONS**********************************************

use "temp\dataset with IV.dta", clear

***PREPARE ACCURACY VARIABLES - Analogous to how we did it for the JOP article

//The Swiss data are not included here, they did not estimate general public opinion
drop if V2==3

//Drop those who made no, or less than 6, general PO estimations 
egen issues_responded_to = total (Q12!=.), by(V3)
drop if issues_responded_to < 6

//DV 1: Incorrect majority placements (GENERAL PUBLIC OPINION)

	*Is an estimation incorrect?
	quietly gen ANOA1=.
	quietly bys V2 SID: replace ANOA1=0 if (Q12>50&cou_agr_cal>50)|(Q12<50&cou_agr_cal<50)|Q12==50
	quietly bys V2 SID: replace ANOA1=1 if (Q12>50&cou_agr_cal<50)|(Q12<50&cou_agr_cal>50)
	quietly bys V2 SID: replace ANOA1=. if Q12==.|cou_agr_cal==.
	
	*Score at the level of the individual politician
	bys V3: egen nr_incorrect= sum(ANOA1)
	
	*Relative to the number of ratings made (percentage)
	gen nr_incorrect_rel = nr_incorrect / issues_responded_to
	
	*Rescale to 8
	gen GPA = round(nr_incorrect_rel * 8)
	
//DV2: percentage point inaccuracy (GENERAL PUBLIC OPINION)

	*Absolute distance between estimation and actual figure
	gen ANOA11=(abs(Q12-cou_agr_cal))
	bys V3: egen inaccuracy_percentage_general= mean(ANOA11) 
	
//Keep one line per respondent
duplicates drop V3, force

tab V2 elite
sum GPA
sum inaccuracy_percentage_general

//Table SM5.1
*Model 1
poisson GPA elite sex age opposition_party i.V2
margins, at(elite=(0 1)) atmeans
*Model 2
poisson GPA seniority sex age opposition_party i.V2
margins, at(seniority=(1 9 17)) atmeans
*Model 3
reg inaccuracy_percentage_general elite sex age opposition_party i.V2
margins, at(elite=(0 1)) atmeans
reg, level(90)
*Model 4
reg inaccuracy_percentage_general seniority sex age opposition_party i.V2
margins, at(seniority=(1 9 17)) atmeans
reg, level(90)

*Footnote 3
poisson GPA c.seniority##c.seniority sex age opposition_party i.V2
reg inaccuracy_percentage_general c.seniority##c.seniority sex age opposition_party i.V2

//Table SM5.3
*Model 1
poisson GPA elite_current sex age opposition_party i.V2
margins, at(elite_current =(0 1)) atmeans
*Model 2
reg inaccuracy_percentage_general elite_current sex age opposition_party i.V2
margins, at(elite_current =(0 1)) atmeans

//Table SM6.1
*Model 1
poisson GPA nr_nominations sex age opposition_party i.V2
margins, at(nr_nominations=(0 1 2 3)) atmeans
*Model 2
reg inaccuracy_percentage_general nr_nominations sex age opposition_party i.V2
margins, at(nr_nominations=(0 1 2 3)) atmeans


*************************PARTY ELECTORATE ESTIMATIONS*********************************************************

use "temp\dataset with IV.dta", clear

*Table SM6.1
preserve
	duplicates drop V3, force
	tab nr_nominations
restore

***PREPARE ACCURACY VARIABLES - Analogous to how we did it for the JOP article

//Drop those who made less than 6 estimations / Too small parties (with unreliable PO estimates)
egen issues_responded_to_ele = total (Q16!=.), by(V3)
drop if issues_responded_to_ele < 6

//DV3: Incorrect majority placements (PARTY ELECTORATE OPINION)

	*Is an estimation correct?
	quietly gen APOA1=.
	quietly bys V2 SID: replace APOA1=0 if (Q16>50&ele_agr_cal>50)|(Q16<50&ele_agr_cal<50)|Q16==50|ele_agr_cal==50
	quietly bys V2 SID: replace APOA1=1 if (Q16>50&ele_agr_cal<50)|(Q16<50&ele_agr_cal>50)
	quietly bys V2 SID: replace APOA1=. if Q16==.|ele_agr_cal==.
	
	*Sum across individuals
	bys V3: egen nr_incorrect_ele= sum(APOA1)
	replace nr_incorrect_ele = . if ele_agr_cal==.
	
	*Relative to the number of ratings made (percentage)
	gen nr_incorrect_ele_rel = nr_incorrect_ele / issues_responded_to_ele
	
	*Rescale to 8
	gen PEA = round(nr_incorrect_ele_rel * 8)

//DV4: percentage point inaccuracy (PARTY ELECTORATE ESTIMATIONS)
	
	*Absolute distance between estimation and actual figure
	gen APOA11=(abs(Q16-ele_agr_cal))
	bys V3: egen inaccuracy_percentage_electorate= mean(APOA11)
	replace inaccuracy_percentage_electorate=. if issues_responded_to_ele < 6	//Were dropped before

//Keep one line per respondent.
duplicates drop V3, force

tab V2 elite
sum PEA
sum inaccuracy_percentage_electorate

//Table SM5.2
*Model 1
poisson PEA elite sex age opposition_party i.V2
margins, at(elite=(0 1)) atmeans
*Model 2
poisson PEA seniority sex age opposition_party i.V2
margins, at(seniority=(1 9 17)) atmeans
*Model 3
reg inaccuracy_percentage_electorate elite sex age opposition_party i.V2
margins, at(elite=(0 1)) atmeans
reg, level(90)
*Model 4
reg inaccuracy_percentage_electorate seniority sex age opposition_party i.V2
margins, at(seniority=(1 9 17)) atmeans
reg, level(90)

*Footnote 3
poisson PEA c.seniority##c.seniority sex age opposition_party i.V2
reg inaccuracy_percentage_electorate c.seniority##c.seniority sex age opposition_party i.V2

//Table SM5.3
*Model 3
poisson PEA elite_current sex age opposition_party i.V2
margins, at(elite_current =(0 1)) atmeans
*Model 4
reg inaccuracy_percentage_electorate elite_current sex age opposition_party i.V2
margins, at(elite_current =(0 1)) atmeans

//Table SM6.2
*Model 3
poisson PEA nr_nominations sex age opposition_party i.V2
margins, at(nr_nominations=(0 1 2 3)) atmeans
*Model 4
reg inaccuracy_percentage_electorate nr_nominations sex age opposition_party i.V2
margins, at(nr_nominations=(0 1 2 3)) atmeans


